//登录业务处理
var { user } = require('../dao/index.js')
async function login(data) {
    var info = null;
    if (!data.user_id || !data.password) {
        info = {
            status: false,
            err: '参数错误'
        }
    } else {
        await user.find({ studentNumber: data.user_id }, function (err, res) {
            if (err) {
                console.log(err)
            }
            if (res.length==0) {
                info = {
                    status: false,
                    err: '用户未注册'
                }
            } else {
                if (res[0].password == data.password) {
                    info = {
                        status: true,
                        lay: '登录成功',
                        token: res[0]._id
                    }
                } else {
                    info = {
                        status: false,
                        err: '密码错误'
                    }
                }
            }
        })
    }
    return info
}

module.exports.login = login